<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>惰性函数</title>
</head>
<body>
    <script>
        function text(num){
            if(num === 1){
                text = function(){   //重写了text方法，之后执行的text方法，就是执行这个函数
                    console.log("内容1");
                }
            }else if(num === 2){
                text = function(){
                    console.log("内容2");
                }
            }else{
                text = function(){
                    console.log("内容3");
                }
            }
            return text();
        }

        text(1);
        text(2);
        // 结果都是：内容1
    </script>
</body>
</html>
